namespace Hack.Decompiling.PEA.DOS
{
  using System;
  using System.IO;
  using System.Diagnostics;
  using System.Collections.Generic;

  /// <summary>
  /// Stubs for DOS
  /// </summary>
  public static class Stubs
  {
    public const int PEStubLength = 64;
    public const int PECodeLength = 14;
    public const int PEDataLength = 50;

    /// <summary>
    /// Standard stub code for PE files in DOS header (64 Bytes)
    /// </summary>
    /// <remarks>
    /// Offset     00 01 02 03 04 05 06 07  08 09 0A 0B 0C 0D 0E 0F
    /// 00000040   0E 1F BA 0E 00 B4 09 CD  21 B8 01 4C CD 21 54 68 
    /// 00000050   69 73 20 70 72 6F 67 72  61 6D 20 63 61 6E 6E 6F 
    /// 00000060   74 20 62 65 20 72 75 6E  20 69 6E 20 44 4F 53 20 
    /// 00000070   6D 6F 64 65 2E 0D 0D 0A  24 00 00 00 00 00 00 00 
    /// </remarks>
    public static readonly byte[] PE = 
    {
      //CODE(CS:0x0000) 14Bytes
      0x0E,             //PUSH CS
      0x1F,             //POP  DS
      0xBA, 0x0E, 0x00, //MOV  DX,0x000E
      0xB4, 0x09,       //MOV  AH,0x09
      0xCD, 0x21,       //INT  0x21      ;INT  0x21(AH = 0x09, DX = 0x000E): DISPLAY STRING AT DS:0x000E ENDS WITH '$'
      0xB8, 0x01, 0x4C, //MOV  AX,0x4C01
      0xCD, 0x21,       //INT  0x21      ;INT  0x21(AH = 0x4C, AL = 0x01): TERMINATE PROCESS WITH CODE 0x01 RETURNED
      //DATA(CS:0x000E):50Bytes
      //"This program cannot be run in DOS mode.\r\r\n$"
	    0x54, 0x68, 0x69, 0x73, 0x20, 0x70, 0x72, 0x6F, 
      0x67, 0x72, 0x61, 0x6D, 0x20, 0x63, 0x61, 0x6E, 
	    0x6E, 0x6F, 0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 
      0x75, 0x6E, 0x20, 0x69, 0x6E, 0x20, 0x44, 0x4F, 
	    0x53, 0x20, 0x6D, 0x6F, 0x64, 0x65, 0x2E, 0x0D, 
      0x0D, 0x0A, 0x24,

      //Padding Zeros.
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
    };
  }

}
